package com.imooc.admin.controller;

import com.imooc.admin.service.FriendLinkService;
import com.imooc.api.controller.admin.FriendLinkControllerApi;
import com.imooc.api.controller.user.BaseControllerApi;
import com.imooc.enums.YesOrNo;
import com.imooc.grance.result.GraceJsonResult;
import com.imooc.pojo.bo.SaveFriendLinBO;
import com.imooc.pojo.mo.FriendLinKMO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @auther Levi
 * @Date: 2021/03/21/16:00
 * @Description:
 */
@RestController
public class FriendLinkController extends BaseControllerApi implements FriendLinkControllerApi {

    @Autowired
    private FriendLinkService friendLinkService;
    @Override
    public GraceJsonResult saveOrUpdateFriendLink(@Valid SaveFriendLinBO saveFriendLinBO) {

        //2.获取属性，赋值属性
        FriendLinKMO friendLinKMO = new FriendLinKMO();
        BeanUtils.copyProperties(saveFriendLinBO, friendLinKMO);
        friendLinKMO.setCreateTime(new Date());
        friendLinKMO.setUpdateTime(new Date());

        //3.保存到mongodb
        friendLinkService.saveOrUpdateFriendLink(friendLinKMO);
        return GraceJsonResult.ok();
    }

    @Override
    public GraceJsonResult getFriendLinkList() {
        List<FriendLinKMO> friendLinkList = friendLinkService.getFriendLinkList();
        return GraceJsonResult.ok(friendLinkList);
    }

    @Override
    public GraceJsonResult delete(String linkId) {
        friendLinkService.delete(linkId);
        return GraceJsonResult.ok();
    }

    @Override
    public GraceJsonResult getPortalFriendLinkList(Integer isDelete) {
        List list = friendLinkService.queryPortalFriendLinkList(YesOrNo.NO.type);
        return GraceJsonResult.ok(list);
    }

}
